using Services;
using UnityEngine;

[DefaultExecutionOrder(-200)]
public class CommonUI : MyCanvasGrounp
{
    private static CommonUI self;
    public static T GetUIComponent<T>() where T : Component
    {
        return self.GetComponentInChildren<T>();
    }

    protected override void Awake()
    {
        base.Awake();
        self = this;
        DontDestroyOnLoad(gameObject);
        immediate_next = true;
        Visible = false;
        EventSystem eventSystem = ServiceLocator.Get<EventSystem>();
        eventSystem.AddListener<int>(EEvent.AfterLoadScene, AfterLoadScene);
    }

    private void AfterLoadScene(int index)
    {
        immediate_next = true;
        Visible = SceneController.InGame;
    }
}
